var DragEle = (function () {
    function DragEle(ele) {
        this.target = ele;
    }
    DragEle.prototype.init = function () {
        this.randColor();
        this.dragStart();
    };
    DragEle.prototype.dragStart = function () {
        var _this = this;
        this.target.onmousedown = function (evt) {
            var posX = evt.offsetX;
            var posY = evt.offsetY;
            console.log(posX, posY);
            _this.posX = posX;
            _this.posY = posY;
            console.log(_this);
            _this.target.style.zIndex = "99999";
            _this.dragMove();
            _this.dragEnd();
        };
    };
    DragEle.prototype.dragMove = function () {
        var _this_1 = this;
        document.onmousemove = function (evt) {
            var x = evt.pageX - _this_1.posX;
            var y = evt.pageY - _this_1.posY;
            _this_1.target.style.left = x + "px";
            _this_1.target.style.top = y + "px";
        };
    };
    DragEle.prototype.dragEnd = function () {
        document.onmouseup = function () {
            document.onmousemove = null;
            this.target.style.zIndex = 0;
        }.bind(this);
    };
    DragEle.prototype.randColor = function () {
        var colorStr = "#";
        for (var i = 0; i < 6; i++) {
            var num = Math.round(Math.random() * 16);
            var char = num.toString(16);
            colorStr += char;
        }
        this.target.style.backgroundColor = colorStr;
    };
    return DragEle;
}());
